import {login} from '@/network/login'
import {REMOVE_TOKE, SET_TOKE} from '@/store/mutations-types'
import {errorMessage} from '@/plugins/message'

/**
 * @author 太阳当空丶赵
 * @date 2022/11/14-21:35
 * @version 1.0.0
 * actions
 */
export default {
    async login({commit}, loginForm) {
        try {
            const {code, data, msg} = await login(loginForm)
            if (code === 200 && data) {
                commit(SET_TOKE, data)
                return true
            } else {
                errorMessage(msg)
                return false
            }
        } catch (e) {
            errorMessage(e)
            return false
        }
    },

    async logout({commit}) {
        try {
            commit(REMOVE_TOKE)
        } catch (e) {

        }
    }
}
